/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.wx.timerTask;

import cn.ac.iie.di.wx.common.RuntimeEnv;
import cn.ac.iie.di.wx.redis.RedisUtil;
import cn.ac.iie.di.wx.utils.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public class CountTask extends TimerTask {

    static Logger logger = Logger.getLogger(CountTask.class.getName());
    private int cout = 0;
    public RedisUtil redisUtil;

    public CountTask(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    @Override
    public void run() {
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//设置日期格式
        String dfDate = df.format(date);
        if (dfDate.equals("23:59:59")) {
            logger.info("picDownload: " + RuntimeEnv.wxPictureUrlQueryCount.get());
            logger.info("init cout value");
            RuntimeEnv.wxFansCntQueryCount.set(0);
            RuntimeEnv.wxReadCntCount.set(0);
            RuntimeEnv.wxRealIdQueryCount.set(0);
            RuntimeEnv.wxPictureUrlQueryCount.set(0);
            //图片下载接口清零
            RuntimeEnv.wxPictureUrlQueryLimit.set(0);
            RuntimeEnv.wxFansCntQueryLimit.set(0);
            RuntimeEnv.wxReadCntLimit.set(0);
            RuntimeEnv.wxRealIdQueryLimit.set(0);
        }
        //设置时间间隔
        int per = 59;
        if (cout < per) {
            ++cout;
        } else {
            logger.info("picDownload: " + RuntimeEnv.wxPictureUrlQueryCount.get());
            cout = 0;
            String todayDate = DateUtil.getToDayDate();
//            redisUtil.set("nrd_" + todayDate, String.valueOf(RuntimeEnv.wxReadCntCount.get()));
//            redisUtil.set("nfans_" + todayDate, String.valueOf(RuntimeEnv.wxFansCntQueryCount.get()));
//            redisUtil.set("uid_" + todayDate, String.valueOf(RuntimeEnv.wxRealIdQueryCount.get()));
            redisUtil.set("pic_" + todayDate, String.valueOf(RuntimeEnv.wxPictureUrlQueryCount.get()));
            logger.info("update to redis key " + "pic_" + todayDate + ",value is " + redisUtil.get("pic_" + todayDate));
//在这进行发送回传计算所的post
            //添加微信管控接口，暂时未定是否要开发
        }

    }

}
